from flask import Flask,render_template
import operate_es

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/insert_single',methods=['POST','GET'])
def insert_single():
    if requests.method=="GET":
        print "GET"
        return render_template('insert_single.html',message='GET')
    else:
        print "POST"
        id = requests.form['ID']
        data = requests.form['data']
        message = operate_es.insert_single(id,data)
        return render_template('insert_single_alert.html',message)

@app.route('/insert_batch',method=['POST','GET'])
def insert_batch():
    if requests.method=='GET':
        print "GET"
        return render_template('insert_batch.html',message="GET")
    else:
        print "POST"
        id1 = requests.form['ID1']
        id2 = requests.form['ID2']
        data = requests.form['data']
        message = operate_es.insert_batch(id1,id2,data)
        return render_template('insert_batch_alert.html',message)

@app.route('/get_single',methods=['POST','GET'])
def get_single():
    if request.method=="GET":
        print("GET")
        return render_template('get_single.html',message='GET')
    else:
        print("POST")
        id = requests.form['ID']
        message = operate_es.get_single(id)
        for i in message:
            print (i)
        return render_template('get_single_alert.html',message)

@app.route('/delete_single',method=['POST','GET'])
def delete_single():
    if requests.method=="GET":
        print "GET"
        return render_template('delete_single.html',message='GET')
    else:
        print("POST")
        id = requests.form['ID']
        message = operate_es.delete_single(id)
        return render_template('delete_single_alert.html',message)

@app.route('/delete_batch',method=['GET','POST'])
def delete_batch():
    if requests.method=='GET':
        print "GET"
        return render_template("delete_batch.html",message="GET")
    else:
        print "POST"
        id1 = requests.form['ID1']
        id2 = requests.form['ID2']
        message = operate_es.delete_batch(id1,id2)
        return render_template("delete_batch_alert.html",message)

@app.route('/delete_query',method=['GET','POST'])
def delete_query():
    if requests.method=='GET':
        print "GET"
        return render_template('delete_query.html',message='GET')
    else:
        print "POST"
        dict['column1'] = requests.form['column1']
        dict['column2'] = requests.form['column2']
        mesaage = operate_es.delete_query(dict)
        return render_template('delete_query_alert.html',message)

if __name__ ==" __main__":
    app.run(debug=True,host="192.168.159.131",port=5000)


